/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).ready(function(){
    var front_server = $("#front-server").val();    
    $(".goods-autohlist").on('click','.goods-auth',function(){
        var goodsid = $(this).attr('data-goodsid');
        var goodsname = $(this).attr('data-goodsname');
        $params = JSON.stringify({'goods_id':goodsid});
        $info_back = ajaxSynchroRequest("/admingoods/default/auth",$params);
        console.log($info_back);
        var attr_html = '';
        $.each($info_back.data.attrs,function(index,value){
            attr_html += '<p>'+value.name+'：'+value.val+'</p>';
        });
        var img_html = '';
        $.each($info_back.data.imgs,function(index,value){
            img_html += '<div class="layui-col-sm12 layui-col-md4"><img class="p border bg-white" src="'+value.src+'"></div>';
        });
        
        contentHtml = '<div class="p30 layui-form"><div class="f18 bg-gray p10">审核商品：【'+goodsname+'】</div><div class="cate-table-outter">'+
                '<table class="layui-table">'+
				'<colgroup>'+
				    '<col width="200">'+
				   ' <col>'+
				 '</colgroup>'+
                    '<tr><td>商品名称：</td><td>'+goodsname+'</td></tr>'+
                    '<tr><td>商品类型：</td><td>'+$info_back.data.first_cate+'>'+$info_back.data.second_cate+'>'+$info_back.data.third_cate+'</td></tr>'+
                    '<tr><td>卖家信息：</td><td>'+$info_back.data.seller+'【'+$info_back.data.seller_id+'】'+'</td></tr>'+
                    '<tr><td>商品属性：</td><td>'+attr_html+'</td></tr>'+
                    '<tr><td>商品图片：</td><td><div class="layui-row layui-col-space20">'+img_html+'</div></td></tr>'+
                    '<tr><td>审核：</td><td><select name="status" id="status" lay-verify="required"><option value="1">审核通过</option><option value="3">未通过</option></select></td></tr>'+
                    '<tr id="tr-reason" class="tr-reason"><td>未通过原因：</td><td><textarea class="layui-textarea" id="reason-textarea" name="optional" placeholder="请输入未通过原因"></textarea></td></tr>'+
                '</table>'+
                '</div></div>';
		
		layui.use('form', function(){
			var form = layui.form;
			$goods_auth_view = layer.open({
			    type: 1,
				title:'商品审核',
			    content: contentHtml,
				area: ['90%', '90%'],
				maxmin: true,
				btn: ['提交', '取消'],
				btnAlign: 'c',
				success: function(layero, index){
					form.render();
				},
				yes: function(index, layero){
				    var status = $("#status option:selected").val();
				    var reason = $("#reason-textarea").val();			    
				    $params = JSON.stringify({'goods_id':goodsid,'status':status,'reason':reason});
				    $create_back = ajaxSynchroRequest("/admingoods/default/auth",$params);
				    console.log($create_back);
				    if($create_back.success===1){
						layer.msg($create_back.msg);
				        layer.close($goods_auth_view);
				        $("#goods-"+goodsid).remove();
				    }
					else{
						layer.msg($create_back.msg);
					}
				  }
				
			});
		  
		});
        
        $("#status").change(function(){
            var selected_status = $("#status option:selected").val();
            if(selected_status == 3){
                $("#tr-reason").show();
            }else{
                $("#tr-reason").hide();
            }
            console.log(selected_status);
        });
    });
});



